/*
 * StringTemplateView.java
 *
 * Copyright 2010 Jack Leow
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package my.edu.clhs.springframework.web.servlet.view.stringtemplate3;

import my.edu.clhs.stringtemplate.servlet.ServletContextStringTemplateGroup;

import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * View using the StringTemplate template engine.
 * 
 * TODO perform design review.
 * TODO add unit tests.
 * 
 * @author Jack Leow
 * @version 1.0
 * @since 1.0 (Mar 6, 2010, 7:09:00 PM)
 */
public class StringTemplateView extends AbstractStringTemplateView {
    private static final Log log =
        LogFactory.getLog(StringTemplateView.class);
    
    // @Override
    protected StringTemplateGroup createTemplateLoader() {
        log.debug("entering createTemplateLoader()");
        StringTemplateGroup templateLoader =
            new ServletContextStringTemplateGroup(
            getTemplateLoaderPath(), getServletContext());
        
        getStringTemplateSupport().
            appendServletUtilTemplateGroup(templateLoader);
        
        String encoding = getEncoding();
        if (encoding != null) {
            templateLoader.setFileCharEncoding(encoding);
        }
        
        log.debug("exiting createTemplateLoader()");
        return templateLoader;
    }
    
    protected StringTemplate loadTemplate(String templateName) {
        log.debug("entering loadTemplate(String)");
        log.debug("exiting loadTemplate(String)");
        return getStringTemplateSupport().
            loadViewTemplate(templateName, getTemplateLoader());
    }
}